/**
 * Copyright &copy; 2012-2016 <a href="https://github.com/thinkgem/jeesite">JeeSite</a> All rights reserved.
 */
package com.thinkgem.jeesite.modules.acq.web.dxdan;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.mvc.support.RedirectAttributes;

import com.thinkgem.jeesite.common.config.Global;
import com.thinkgem.jeesite.common.persistence.Page;
import com.thinkgem.jeesite.common.web.BaseController;
import com.thinkgem.jeesite.common.utils.StringUtils;
import com.thinkgem.jeesite.modules.acq.entity.dxdan.AcqDxdan;
import com.thinkgem.jeesite.modules.acq.service.dxdan.AcqDxdanService;

/**
 * 订销单Controller
 * @author lj
 * @version 2018-05-04
 */
@Controller
@RequestMapping(value = "${adminPath}/acq/dxdan/acqDxdan")
public class AcqDxdanController extends BaseController {

	@Autowired
	private AcqDxdanService acqDxdanService;
	
	@ModelAttribute
	public AcqDxdan get(@RequestParam(required=false) String id) {
		AcqDxdan entity = null;
		if (StringUtils.isNotBlank(id)){
			entity = acqDxdanService.get(id);
		}
		if (entity == null){
			entity = new AcqDxdan();
		}
		return entity;
	}
	
	@RequiresPermissions("acq:dxdan:acqDxdan:view")
	@RequestMapping(value = {"list", ""})
	public String list(AcqDxdan acqDxdan, HttpServletRequest request, HttpServletResponse response, Model model) {
		Page<AcqDxdan> page = acqDxdanService.findPage(new Page<AcqDxdan>(request, response), acqDxdan); 
		model.addAttribute("page", page);
		return "modules/acq/dxdan/acqDxdanList";
	}

	@RequiresPermissions("acq:dxdan:acqDxdan:view")
	@RequestMapping(value = "form")
	public String form(AcqDxdan acqDxdan, Model model) {
		model.addAttribute("acqDxdan", acqDxdan);
		return "modules/acq/dxdan/acqDxdanForm";
	}

	@RequiresPermissions("acq:dxdan:acqDxdan:edit")
	@RequestMapping(value = "save")
	public String save(AcqDxdan acqDxdan, Model model, RedirectAttributes redirectAttributes) {
		if (!beanValidator(model, acqDxdan)){
			return form(acqDxdan, model);
		}
		acqDxdanService.save(acqDxdan);
		addMessage(redirectAttributes, "保存订销单成功");
		return "redirect:"+Global.getAdminPath()+"/acq/dxdan/acqDxdan/?repage";
	}
	
	@RequiresPermissions("acq:dxdan:acqDxdan:edit")
	@RequestMapping(value = "delete")
	public String delete(AcqDxdan acqDxdan, RedirectAttributes redirectAttributes) {
		acqDxdanService.delete(acqDxdan);
		addMessage(redirectAttributes, "删除订销单成功");
		return "redirect:"+Global.getAdminPath()+"/acq/dxdan/acqDxdan/?repage";
	}

}